package com.zhao.demo.unbound.demo03_source.sample06_fromjavacollection

import java.util
import java.util.Collections

import com.zhao.entity.MiddleStudent
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment

/**
 * Description: 使用source阶段的算子之fromCollection,将java中集合封装到DataStream中<br/>
 * Copyright (c) ，2020 ， 赵 <br/>
 * This program is protected by copyright laws. <br/>
 * Date： 2020/11/30 14:38
 *
 * @author 柒柒
 * @version : 1.0
 */

object FromJavaCollectionDemo {
  def main(args: Array[String]): Unit = {
    //1.环境
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    //实时读取流数据,计算,并显示结果
    import org.apache.flink.api.scala._

    //将Java中集合封装到DataStream
    val container: util.LinkedList[MiddleStudent] = new util.LinkedList[MiddleStudent]()

    Collections.addAll(
      container,
      new MiddleStudent("张三",55.55),
      new MiddleStudent("李四",66.66),
      new MiddleStudent("王五",99.99)
    )
    //导入JavaConverions单例类中的隐式方法,自动将java中的集合与scala中的集合根据需求,自动进行转换
    import scala.collection.JavaConversions._
    env.fromCollection(container)
      .print("将java中的集合封装到DataStream->")

    //3.启动应用
    env.execute(this.getClass.getSimpleName)
  }
}









